package ThreadPoolDemo.bilibiliThread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolTest {
	public static void main(String[] args) {
		// ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(3);
		ExecutorService newFixedThreadPool = Executors.newCachedThreadPool();
		// ExecutorService newFixedThreadPool = Executors
		// .newSingleThreadExecutor();

		for (int i = 0; i < 10; i++) {
			final int task = i;
			newFixedThreadPool.execute(new Runnable() {
				@Override
				public void run() {
					if (task == 5) {
						int a = Integer.parseInt("a");
					}
					for (int j = 1; j < 10; j++) {
						System.out.println(Thread.currentThread().getName()
								+ "loop of " + j + "for task of" + task);
					}
				}
			});
		}
		newFixedThreadPool.shutdown();
		// Executors.newScheduledThreadPool(1).scheduleAtFixedRate(new
		// Runnable() {
		//
		// @Override
		// public void run() {
		// System.out.println("boom!!");
		//
		// }
		// }, 10, 2, TimeUnit.SECONDS);
	}
}
